// TodoList.java
import java.util.ArrayList;
import java.util.Scanner;

public class TodoList {
    public static void main(String[] args) {
        ArrayList<String> tasks = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        String command;

        System.out.println("简单的待办事项列表");
        System.out.println("命令: add <任务内容>, list, remove <任务编号>, exit");

        while (true) {
            System.out.print("> ");
            command = scanner.nextLine().trim();
            String[] parts = command.split(" ", 2);
            String action = parts[0].toLowerCase();

            if (action.equals("exit")) {
                System.out.println("再见!");
                break;
            }

            switch (action) {
                case "add":
                    if (parts.length > 1 && !parts[1].isEmpty()) {
                        tasks.add(parts[1]);
                        System.out.println("任务已添加: \"" + parts[1] + "\"");
                    } else {
                        System.out.println("用法: add <任务内容>");
                    }
                    break;
                case "list":
                    if (tasks.isEmpty()) {
                        System.out.println("没有待办事项。");
                    } else {
                        System.out.println("\n待办事项:");
                        for (int i = 0; i < tasks.size(); i++) {
                            System.out.println((i + 1) + ". " + tasks.get(i));
                        }
                    }
                    break;
                case "remove":
                    if (parts.length > 1) {
                        try {
                            int taskNumber = Integer.parseInt(parts[1]);
                            if (taskNumber > 0 && taskNumber <= tasks.size()) {
                                String removedTask = tasks.remove(taskNumber - 1);
                                System.out.println("任务已移除: \"" + removedTask + "\"");
                            } else {
                                System.out.println("无效的任务编号。");
                            }
                        } catch (NumberFormatException e) {
                            System.out.println("无效的任务编号，请输入数字。");
                        }
                    } else {
                        System.out.println("用法: remove <任务编号>");
                    }
                    break;
                default:
                    System.out.println("未知命令。可用命令: add, list, remove, exit");
                    break;
            }
        }
        scanner.close();
    }
}